class Solution
{
public:
    int addMinimum(string word)
    {
        int n = word.size();
        int i = 0;
        int insertCount = 0;
        while (i < n)
        {
            switch (word[i])
            {
            case 'a':
            {
                if (i + 2 < n && word[i + 1] == 'b' && word[i + 2] == 'c')
                {
                    i += 3;
                }
                else if (i + 1 < n && (word[i + 1] == 'b' || word[i + 1] == 'c'))
                {
                    insertCount += 1;
                    i += 2;
                }
                else
                {
                    insertCount += 2;
                    i += 1;
                }
                break;
            }
            case 'b':
            {
                if (i + 1 < n && word[i + 1] == 'c')
                {
                    insertCount += 1;
                    i += 2;
                }
                else
                {
                    insertCount += 2;
                    i += 1;
                }
                break;
            }
            case 'c':
            {
                insertCount += 2;
                i += 1;
                break;
            }
            }
        }
        return insertCount;
    }
};